<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="net.sf.rose.business.bean.action.ActionUnitUpdateBean" %>
<%@include file="/common/header.jsp"%>
<c:set var="path" value="..${ctx}/define/actionunit"/>

<div class="pageContent">

	<div class="panelBar">
		<ul class="toolBar">
			<li><a class="edit" onclick="save();" title="保存"><span>保存</span></a></li>
			<li class="line">line</li>
			<li><a class="delete" onclick="deleteAction();"><span>删除</span></a></li>
		</ul>
	</div>

	<form name="form" method="post" action="${path}/save.html" class="pageForm required-validate" onsubmit="return validateCallback(this, dialogAjaxDone);">
		<input type="hidden" id="actionType" name="actionType" value="${actionType}" />
		<div class="pageFormContent" layoutH="75">
			<fieldset layoutH="80">
				<legend>基本信息</legend>
				<dl >
					<dt>操作名称：</dt>
					<dd><input name="name" type="text" size="30" value="${bean.name}" class="required" /></dd>
				</dl>
				<dl >
					<dt>分类：</dt>
					<dd><input name="sort" type="text" size="30" value="${bean.sort}" class="required" /></dd>
				</dl>
				<dl >
					<dt>更新类型：</dt>
					<dd>
						<select class="combox" name="type">
							<option <c:if test="${bean.type=='update'}">selected</c:if> value="update">更新</option>
							<option <c:if test="${bean.type=='delete'}">selected</c:if> value="delete">删除</option>
						</select>
					</dd>
				</dl>
				<dl >
					<dt>表名：</dt>
					<dd>
					<input name="table.id" type="hidden" value="${bean.table}" />
					<input name="table.name" type="text" value="${bean.tableBean.text}" class="required" />
					<a class="btnLook" href="..${ctx}/common/view.html?jsp=define/database/table_list" lookupGroup="table">查找带回</a>
					</dd>
				</dl>
				<dl class="nowrap">
					<dt>刷新单元：</dt>
					<dd >
					<%
						ActionUnitUpdateBean bean = (ActionUnitUpdateBean) request.getAttribute("bean");
						java.util.List<String> refreshList = bean.getRefresh();
						StringBuffer refresh = new StringBuffer();
						if (refreshList != null && refreshList.size() > 0) {
							for (String rule : refreshList) {
								refresh.append(rule).append(',');
							}
							refresh.deleteCharAt(refresh.length() - 1);
						}
					%>
					<input id="refresh_name" name="refresh.name" type="text" size="83" value="<%=refresh.toString()%>" />
					<a class="btnLook" href="javascript:open_refresh_consult('选择查询操作单元');" >查找带回</a>
					</dd>
				</dl>
				<dl>
					<dt>批量更新前缀：</dt>
					<dd><input name="batchPre" type="text" size="30" value="${bean.batchPre}" /></dd>
				</dl>
				<dl>
					<dt>操作说明：</dt>
					<dd><input name="description" type="text" size="30" value="${bean.description}" /></dd>
				</dl>
				<dl class="nowrap">
					<dt>规则代码：</dt><br><br>
					<dd><textarea name="rules" cols="115" rows="4" ><c:out value="${bean.rules}" /></textarea></dd>
				</dl>
				<dl >
					<dt>规则说明：</dt><br><br>
					<dd><textarea name="ruleDescription" cols="115" rows="4" ><c:out value="${bean.ruleDescription}" /></textarea></dd>
				</dl>
			</fieldset>
			</div>



	</form>
</div>
<script type="text/javascript">
/**
 * dialog上的表单提交回调函数
 * 服务器转回navTabId，可以重新载入指定的navTab. statusCode=DWZ.statusCode.ok表示操作成功, 自动关闭当前dialog
 * form提交后返回json数据结构,json格式和navTabAjaxDone一致
 */
function dialogAjaxDone(json){
	DWZ.ajaxDone(json);
	if (json.statusCode == DWZ.statusCode.ok){
		// alertMsg.correct(json.message);
		if(json.callbackType){
			var url = "${path}/list.html";
			navTab.reload(url,null,"base_define_action_unit_list");
			// navTab.reload(url);
			//navTab.reloadFlag("base_define_action_list"); // 下次切换到列表页签时需要刷新一下
			setTimeout(function(){$.pdialog.closeCurrent();}, 100); // 关闭此编辑页签
		}
	}
}

function save(){
	$(form).submit();
}

function deleteAction(){
	var rel = '';
	$('.base_define_action_unit_list_tr').each(function(){
		if($(this).hasClass("selected")){
			rel = $(this).attr('rel');
		}
	});
	if(rel==''){
		alertMsg.warn('请先选择一条数据！');
	}else{
		alertMsg.confirm("确定要删除吗?", {
			okCall: function(){
				var arr = rel.split(","); //字符分割 
				var url = "${path}/delete.html?type=action&id=" + arr[1];
				$.ajax({
					type: "post", url: url,
					success: function(json){
						alertMsg.correct(json.msg);
						var url = "${path}/list.html";
						navTab.reload(url);
						setTimeout(function(){$.pdialog.closeCurrent();}, 100); // 关闭此编辑页签
					},
					error: function(){
						alertMsg.error('系统错误，请联系管理员！');
					}
				});
			}
		});
	}
}

function open_refresh_consult(title){
	var url = "..${ctx}/define/actionunit/consult.html?js_back_function=consultRefreshBack";
	$.pdialog.open(url, "base_define_action_unit_consult", title,{width:800,height:480,mask:true,maxable:false,resizable:false});
}

function consultRefreshBack(args){
	// 将值部分二次转码，以防出现中文乱码的问题
	var params = encodeURI(encodeURI(args));
	$('#refresh_name').val(params);
	//$("#txt").attr("value",'11');
	// 关闭子参照窗体
	$.pdialog.close("base_define_action_unit_consult");
}

</script>
